#include <iostream>

#include "DTDElement.h"

/**
* Constructeur
*/
DTDElement::DTDElement() : name( "" ), typeDTDElement( E_CHILDREN ), children( NULL )
{
}

DTDElement::DTDElement(ELEMENT_TYPE aType) : name( "" ), typeDTDElement( aType ), children( NULL )
{
}

/**
* Destructeur
*/
DTDElement::~DTDElement()
{
}

const string& DTDElement::getName() const
{
	return name;
}

const ELEMENT_TYPE DTDElement::getType() const
{
	return typeDTDElement;
}

Children* DTDElement::getChildren()
{
	return children;
}

void DTDElement::setName( const string& name )
{
	this->name = name;
}

void DTDElement::setChildren( Children* child )
{
	children = child;
}

void DTDElement::printMe()
{
	cout<<"<!ELEMENT "<<name<<" ";
	switch(typeDTDElement)
	{
		case E_EMPTY:
			cout<<"EMPTY";
			break;
		case E_ANY:
			cout<<"ANY";
			break;
		case E_CHILDREN:
			children->printMe();
			break;
		default: 
			break;
	}
	cout<<">"<<endl;
}

/**
* Retourne l'équivalent en RegExp de l'élément courant
*/
pair<string, regex> DTDElement::toRegExp()
{
	string regexp = "";

	/* En fonction du type de l'élément on ajoute la suite */
	switch( typeDTDElement )
	{
		case E_CHILDREN:
			regexp += children->toRegExp();
			break;
		case E_EMPTY:
			break;
		case E_MIXTE:
			/* Géré par surcharge */
			break;
		case E_ANY:
			regexp += "(#|[a-Z]){1}.*";
			break;
		default:
			break;
	}	
	
	cout << regexp << endl;
	return pair<string, regex>( this->name, regex( regexp ) );
}
